<?php
!defined ('P_W') && exit('Forbidden');
class PW_ImageTypeCache {
	var $topTypes;
	var $secendTypes;
	var $_haveInit=false;
	
	function __construct() {
		//$this->_init();
	}
	function PW_ImageTypeCache() {
		$this->__construct();
	}
	function _initCache() {
		$cacheFile = $this->_getCacheFile();
		if (!is_file($cacheFile)) {
			$this->cacheTypes();
		}
		require Pcv($cacheFile);
		$this->topTypes =& $topTypes;
		$this->secendTypes =& $secendTypes;
		$this->_haveInit = true;
	}
	
	function cacheTypes() {
		$imageTypeDB = House::loadDB('house_imagetype');
		$temp = $imageTypeDB->getAll();
		
		$topTypes = $secendTypes = array();
		foreach ($temp as $key => $imageType) {
			if (!$imageType['sub']) {
				$topTypes[$key] = $imageType;
			} else {	
				$secendTypes[$imageType['sub']][$key] = $imageType;
			}
		}
		$cacheFile = $this->_getCacheFile();
		writeover($cacheFile,"<?php\r\n\$topTypes=".pw_var_export($topTypes).";\r\n\$secendTypes=".pw_var_export($secendTypes).";\r\n?>");
	}
	
	function &getTopTypes() {
		if (!$this->_haveInit) $this->_initCache();
		return $this->topTypes;
	}
	function &getSecendTypes($id) {
		if (!$this->_haveInit) $this->_initCache();
		$id = (int)$id;
		if ($id) {
			return $this->secendTypes[$id];
		}
		return $this->secendTypes;
	}
	function _getCacheFile() {
		return D_P.'data/bbscache/house_imagetype.php';
	}
}
?>